package me.zhengjie.modules.detailed.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.detailed.domain.Detailed;
import me.zhengjie.modules.detailed.service.DetailedService;
import me.zhengjie.modules.detailed.service.dto.DetailedDto;
import me.zhengjie.modules.detailed.service.dto.DetailedQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author lida
* @date 2022-04-25
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "账务管理管理")
@RequestMapping("/api/detailed")
public class DetailedController {

    private final DetailedService detailedService;

    @GetMapping
    @Log("查询账务管理")
    @ApiOperation("查询账务管理")
    public ResponseEntity query(DetailedQueryParam query, Pageable pageable){
        return new ResponseEntity<>(detailedService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增账务管理")
    @ApiOperation("新增账务管理")
    public ResponseEntity create(@Validated @RequestBody DetailedDto resources){
        return new ResponseEntity<>(detailedService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改账务管理")
    @ApiOperation("修改账务管理")
    public ResponseEntity update(@Validated @RequestBody DetailedDto resources){
        detailedService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除账务管理")
    @ApiOperation("删除账务管理")
    @PreAuthorize("@el.check('detailed:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        detailedService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出账务管理")
    @ApiOperation("导出账务管理")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('detailed:list')")
    public void download(HttpServletResponse response, DetailedQueryParam query) throws IOException {
        detailedService.download(detailedService.queryAll(query), response);
    }*/

}
